Cellular automata were invented in the 1950s by John von Neumann as formal models of
self-reproducing machines. The field was revived in the 1980s by Stephen Wolfram.
Wolfram is also the author of the program
are available on his
He has spent the last nine years writing a new book on cellular automata. Titled
A New Kind of Science,
he believes it will revolutionize many fields. An interesting profile
God, Stephen Wolfram, and Everything Else by Michael S. Malone
was recently in Forbes ASAP.
5.1 One-dimensional cellular automata
Our cellular automata consist of a single-dimensional array of cells.
Based on their long-term behavior, Stephen Wolfram divided cellular automata rules
into four distinct classes.
- Each cell can take on the value 0 or 1.
- Each time-step or generation all of the cells can take on a new value.
- The value of a cell at time T+1 is determined by the values of the cell and
its neighbors at time T.
- The transitions are specified in a transition table.
- Here is one based
on the sum of the values of the cell and its two nearest neighbors on each side:
- Transition tables can be encoded into single numbers
above tables based on Introduction to Artificial Life, Christoph Adami, 1998
Wolfram is currently fascinated by class III rule 30
- Class I - limit point behavior
- evolve to a homogeneous state (all zeros or all ones)
- example: code 60 rule
- Black represents value 1, white represents value 0.
- Generations/Time increases downwards.
- Class II - limit cycle behavior
- evolve periodic structures
- example: code 56 rule
- Class III - aperiodic, chaotic behavior
- example: code 10 rule
- Class IV - complex behavior
He sees this pattern in many areas of nature, such as pigmentation on
seashells. He believes cellular automata are the key to understanding how
simple rules produce complex structures and behavior.
Many other variations on cellular automata have been studied:
- Other types of transition tables can be used.
- Cells may take on more states than the simple 1/0 on/off.
- The automata may use two or more dimensions
- The most famous two-dimensional cellular automata is Conway's Life
5.2 Update rules in Python
Here's a Python function to calculate the new value of a cell, given the sum of the
cell and 2 nearest neighbors on each side, and the rule code:
mask = 1 << sum
if (rule & mask) != 0:
You don't have to understand how this function works to use it, but here's an
The rules codes can be represented as binary numbers instead of decimal.
The function uses Python's bit-level operators << and &.
- from the transition table above, rule code 20 becomes 010100
So the function reads the column of the transition table corresponding to
the sum passed in.
- << left shifts the value 1 as many times as the sum.
- & bitwise
ands the mask with the rule.
Yes, if you don't know binary arithmetic this explanation probably doesn't help.
if you want to know more.
5.3 Cellular automata in Python
Your assignment is to write a program to display one-dimensional cellular automata.
First create a list with as many cells (elements) as your chosen screen width.
- The program will repeatedly prompt the user for the rule code,
and generate the display.
To display the list in the window, iterate over each cell and use the
- Build it up from an empty list using the
append method from the
- Initialize each cell with a random value 0 or 1.
To calculate a new generation, first copy the list to a temporary list.
The temporary list now becomes the current list.
- For each cell in the temporary list sum its current value with that of its two
closest neighbors on each side, and call
updateForSum to determine the
- Be sure to handle the neighbor-does-not-exist cases (near the list ends).
During debugging you should use a small display (say 50x50). Generating 400x400
displays takes a LONG time in Python...
- display the new current list one line down
- repeat for height of display window
Don't forget to call
livewires.clear_screen() when you start to
display a new code rule.
Also, the drawable area of the livewires display window appears to be a few pixels
shorter than the requested height. Try leaving a few blank lines at the top to
ensure you are displaying all the data (the first line should always look random).
When your program is working, try out different code rules. You may even find one
that impresses Stephen.